
#include "main.h"
#include "OTSU.h"
#include "my_draw.h"
#include "my_param.h"
#include "perspective.h"
#include "search_border.h"
#include "complement_line.h"
#include "judgment_element.h"

myParam my_param;
ImageInfo image_info;

int vision_main(uint8_t mt9v03x_image[IMAGE_HEIGHT][IMAGE_WIDTH])
{
//	while (1)
//	{
		//Mat src = imread("../18.jpg", 0); // 传入灰度图
//		if (src.empty())
//		{
//			//printf("can not open");
//			continue;
//		}
		//resize(src, src, Size(IMAGE_WIDTH, IMAGE_HEIGHT)); // TODO 此处是为了与源代码兼容
//		imshow("input", src);							   // 支持256 或者浮点数

		//uint8_t mt9v03x_image[IMAGE_HEIGHT][IMAGE_WIDTH]; // 输入原图

		// 模拟总钻风采集图像数组
//		for (int Ysite = 0; Ysite < IMAGE_HEIGHT; Ysite++)
//			for (int Xsite = 0; Xsite < IMAGE_WIDTH; Xsite++)
				//mt9v03x_image[Ysite][Xsite] = src.at<uchar>(Ysite, Xsite);

		/******************逆透视初始化********************/
		ImagePerspective_Init(mt9v03x_image, image_info.RESULT_IMAGE, image_info.ImageDeal);

		/******************大津法算阈值********************/
		uint8 OTSU_Threshold = Get_Threshold(mt9v03x_image[0], IMAGE_HEIGHT, IMAGE_WIDTH);

		/******************大津法二值化********************/
		All_IMAGE_OTSU(image_info.RESULT_IMAGE, image_info.RESULT_IMAGE, RESULT_HEIGHT, RESULT_WIDTH, OTSU_Threshold); // 如果使用逆透视，需要边界数组

		/************二值化图像大津法获取边线*************/
		Search_Border_OTSU(image_info.RESULT_IMAGE, RESULT_HEIGHT, RESULT_WIDTH, RESULT_HEIGHT - 2, image_info); // RESULT_WIDTH - 2行为底行

		/************元素判断*************/
		Judgment_Element(image_info);

		/************补线*************/
		Complement_line(image_info);

		/************画图**************/
		//Mat img(RESULT_HEIGHT, RESULT_WIDTH, CV_8UC1, (unsigned char *)image_info.RESULT_IMAGE);
		//my_draw(img);
		//resize(img, img, Size(RESULT_WIDTH * 5, RESULT_HEIGHT * 5));
		//imshow("image", img);
		//waitKey(1);
	//}
	return 0;
}